import { createRouter, createWebHistory } from 'vue-router';
import Product from '../views/product/index.vue';
import PInfo from '../views/product/detail/index.vue';
import Home from '../views/home/index.vue';
import News from '../views/news/index.vue';
import Arrival from '../views/arrival/index.vue';
import Advance from '../views/advance/index.vue';
import AdvanceDetail from '../views/advance/detail/index.vue';
import NewsDetail from '../views/news/detail/index.vue';
import Board from '../views/board/index.vue';
import Company from '../views/company/index.vue';
import Wholesale from '../views/wholesale/index.vue';
import Search from '../views/search/index.vue';
// 定义路由规则
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
  },
  {
    path: '/product/:typeId?',
    name: 'Product',
    component: Product,
  }, {
    path: '/product/detail',
    name: 'PInfo',
    component: PInfo,
  },
  {
    path: '/news',
    name: 'News',
    component: News,
  },
  {
    path: '/news/detail',
    name: 'NewsDetail',
    component: NewsDetail,
  },
  {
    path: '/arrival',
    name: 'Arrival',
    component: Arrival,
  },
  {
    path: '/advance',
    name: 'Advance',
    component: Advance,
  }, {
    path: '/advance/detail',
    name: 'AdvanceDetail',
    component: AdvanceDetail,
  }, {
    path: '/board',
    name: 'Board',
    component: Board,
  }, {
    path: '/company',
    name: 'Company',
    component: Company,
  }, {
    path: '/wholesale',
    name: 'Wholesale',
    component: Wholesale,
  }, {
    path: '/search',
    name: 'Search',
    component: Search,
  }

];

// 创建路由实例
const router = createRouter({
  history: createWebHistory(), // 使用 HTML5 History 模式
  routes, // 路由规则
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { top: 0 }
  }
});

export default router;